package com.xiaoran.rabbitmq.demo.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.PathVariable;

import javax.annotation.security.PermitAll;

//配置类  发布确认高级

@Configuration
public class Confir_Config {
    //交换机
    public static final  String  confire_exchange_name="confire_exchange";
    //队列
    public static  final String  confire_queue_name="confire_queue";
    //RoutingKey
    public static final  String confire_routing_key="key1";

    //备份交换机
    public static final String backup_exchange_name="backup_exchange";
    //备份队列
    public static final String  backup_queue_name="backup_queue";
    //报警队列
    public static final String  warning_queue_name="warning_queue";
    //交换机
    @Bean
    public DirectExchange directExchange(){
        return ExchangeBuilder.directExchange(confire_exchange_name).durable(true)
                .withArgument("alternate-exchange",backup_exchange_name).build();
    }
    //队列
    @Bean
    public Queue queue(){
        return QueueBuilder.durable(confire_queue_name).build();
    }

    //绑定
    @Bean
    public Binding queue_exchange(@Qualifier("directExchange") DirectExchange  directExchange,@Qualifier("queue") Queue queue) {
        return BindingBuilder.bind(queue).to(directExchange).with(confire_routing_key);
    }

    //备份交换机
    @Bean
    public FanoutExchange fanoutExchange(){
        return new FanoutExchange(backup_exchange_name);
    }
    //注册备份队列
    @Bean
    public Queue queue2(){
        return QueueBuilder.durable(backup_queue_name).build();
    }
    //注册报警队列
    @Bean
    public Queue queue3(){
        return QueueBuilder.durable(warning_queue_name).build();
    }

    //绑定备份队列
    @Bean
    public Binding binding2(@Qualifier("queue2") Queue queue,@Qualifier("fanoutExchange") FanoutExchange fanoutExchange){
        return BindingBuilder.bind(queue).to(fanoutExchange);
    }
    //绑定报警队列
    @Bean
    public Binding binding3(@Qualifier("queue3") Queue queue,@Qualifier("fanoutExchange") FanoutExchange fanoutExchange){
        return BindingBuilder.bind(queue).to(fanoutExchange);
    }
    }
